<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>接口管理</title>
    <jsp:include page="../../../head.jsp"/>
    <script type="text/javascript">
        var dropdownState = $.mrdForm.ajaxdp("dropdown-useState");
        var formSetting = {
            title: "查询公司接口",
            columns: [{
                name: "id",
                label: "公司名称",
                type: "dropdown",
                dropdownType: "ajax",
                minLength: 0,
                url: "dropdown-supCop"
            }, {
                name: "type",
                label: "接口类型",
                type: "dropdown",
                dropdownType: "ajax",
                minLength: 0,
                url: "dropdown-businessType"
            }],
            buttons: {
                custom: [{
                    id: "showList",
                    value: "查看模板",
                    click: function () {
                        jw.dialog({
                                      iframe: 'itf-template',
                                      width: 1000,
                                      height: 600,
                                      over: false
                                  });
                    }
                }, {
                    id: "validate",
                    value: "校验接口",
                    click: function () {
                        var id = $("#itfForm").mrdForm("formVal", "id");
                        if (id) {
                            var data = $.mrdForm.filterObject();
                            $.ajax({
                                       "url": "itf-vitf",
                                       "data": data,
                                       "type": "post",
                                       "success": function (data) {
                                           var its = data.sysInterfaces;
                                           if (its) {
                                               var st = "如下接口不存在：";
                                               $.each(its, function (i, n) {
                                                   if (i % 2 == 0 && i != its.length) {
                                                       st += "<br/>";
                                                   }
                                                   st += n.name + ",";
                                               });
                                               st = st.substring(0, st.length - 1);
                                               jw.alert(st);
                                           } else {
                                               jw.alert("接口全部存在!");
                                           }
                                       }
                                   });
                        } else {
                            jw.alert("请输入需要校验接口的公司!");
                        }
                    }
                }, {
                    id: "create",
                    value: "生成接口",
                    click: function () {
                        var id = $("#itfForm").mrdForm("formVal", "id");
                        if (id) {
                            var data = $.mrdForm.filterObject();
                            jw.confirm("确定生成该公司的接口配置?", function () {
                                $.ajax({
                                           "url": "itf-create",
                                           "data": data,
                                           "type": "post",
                                           "success": function (data) {
                                               var msg = $.parseJSON(data.msg);
                                               if (msg.state == "1") {
                                                   jw.alert(msg.msg);
                                                   $("#itfForm").mrdForm("refreshGrid");
                                               } else {
                                                   jw.alert(msg.msg);
                                               }
                                           }
                                       });
                            });
                        } else {
                            jw.alert("请输入需要生成接口的公司!");
                        }
                    }
                }]
            },
            grid: {
                id: "sys_cop_itfs",
                url: "itf-list",
// 			sortname:"systemInterface.name",
                colModel: [{
                    index: "id",
                    name: "id",
                    hidden: true
                }, {
                    index: "company.name",
                    name: "company.name",
                    label: "公司名称"
                }, {
                    index: "systemInterface.name",
                    name: "systemInterface.name",
                    label: "接口名称"
                }, {
                    index: "systemInterface.type",
                    name: "systemInterface.type",
                    label: "接口类型"
                }, {
                    index: "use_state",
                    name: "use_state",
                    label: "使用状态",
                    dropdown: dropdownState
                }],
                jsonReader: {
//                    root: "systemCopInterfaces"
                }
            }
        };
        $(document).ready(function () {
            $("#itfForm").mrdForm(formSetting);
            $("#itfForm").mrdForm("resize");
        });
    </script>
</head>
<body>
<div id="itfForm"></div>
</body>
</html>
